<template>
  <div class="app-container" v-loading="loading">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="扫码器" prop="bcr">
        <el-input
          v-model="queryParams.bcr"
          placeholder="请输入扫码器"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreateDate"
          size="small"
          style="width: 350px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['wcs:wcs_sorted_status_percent:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table  :data="wcs_sorted_status_percentList" @selection-change="handleSelectionChange" >
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="id" align="center" prop="id" />-->
      <el-table-column label="扫码器" align="center" prop="bcr" />
      <el-table-column label="总数" align="center" prop="total" />
      <el-table-column label="成功率" align="center" prop="successPercent" />
      <el-table-column label="正常" align="center" prop="normal0" />
      <el-table-column label="noread" align="center" prop="noread1" />
      <el-table-column label="未接收bcr信息" align="center" prop="nocode2" />
      <el-table-column label="多条码" align="center" prop="moreBarcode3" />
      <el-table-column label="wcs未反馈" align="center" prop="wcsNoDest4" />
      <el-table-column label="满格" align="center" prop="posFull5" />
      <el-table-column label="格口关闭" align="center" prop="posClose6" />
      <el-table-column label="目的地无效" align="center" prop="unknownDest7" />
      <el-table-column label="跟踪丢失" align="center" prop="trackingError8" />
      <el-table-column label="超圈" align="center" prop="exceedMaxCircle9" />
      <el-table-column label="间距过小" align="center" prop="gadTooSmall10" />
      <el-table-column label="长度错误" align="center" prop="lengthError11" />
      <el-table-column label="状态13" align="center" prop="state13" />
      <el-table-column label="状态99" align="center" prop="state99" />
      <el-table-column label="其他" align="center" prop="other" />
<!--      <el-table-column label="备用1" align="center" prop="temp1" />-->
<!--      <el-table-column label="备用2" align="center" prop="temp2" />-->
<!--      <el-table-column label="备用3" align="center" prop="temp3" />-->
<!--      <el-table-column label="备用4" align="center" prop="temp4" />-->
<!--      <el-table-column label="创建时间" align="center" prop="createDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="更新时间" align="center" prop="updateDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['wcs:wcs_sorted_status_percent:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['wcs:wcs_sorted_status_percent:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listWcs_sorted_status_percent, getWcs_sorted_status_percent, delWcs_sorted_status_percent, addWcs_sorted_status_percent, updateWcs_sorted_status_percent, exportWcs_sorted_status_percent } from "@/api/wcs/wcs_sorted_status_percent";
import { initRangeDate } from '@/api/wcs/general/wcs_tool'

export default {
  name: "Wcs_sorted_status_percent",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 分拣状态统计表格数据
      wcs_sorted_status_percentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 创建时间时间范围
      daterangeCreateDate: [],
      // 更新时间时间范围
      daterangeUpdateDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        bcr: null,
        total: null,
        successPercent: null,
        normal0: null,
        noread1: null,
        nocode2: null,
        moreBarcode3: null,
        wcsNoDest4: null,
        posFull5: null,
        posClose6: null,
        unknownDest7: null,
        trackingError8: null,
        exceedMaxCircle9: null,
        gadTooSmall10: null,
        lengthError11: null,
        state13: null,
        state99: null,
        other: null,
        temp1: null,
        temp2: null,
        temp3: null,
        temp4: null,
        createDate: null,
        updateDate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.daterangeCreateDate = initRangeDate();
    this.getList();
  },
  methods: {
    /** 查询分拣状态统计列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateDate && '' != this.daterangeCreateDate) {
        this.queryParams.params["beginCreateDate"] = this.daterangeCreateDate[0];
        this.queryParams.params["endCreateDate"] = this.daterangeCreateDate[1];
      }
      let startLogTime = Date.parse(new Date());
      // console.log(startLogTime)
      listWcs_sorted_status_percent(this.queryParams).then(response => {
        let endLogTime = Date.parse(new Date());
        // console.log(endLogTime)

        this.wcs_sorted_status_percentList = response.rows;
        this.total = response.total;
        this.loading = false;
        console.log('耗时：'+(Date.parse(new Date())-startLogTime)/1000+'s!')
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        bcr: null,
        total: null,
        successPercent: null,
        normal0: null,
        noread1: null,
        nocode2: null,
        moreBarcode3: null,
        wcsNoDest4: null,
        posFull5: null,
        posClose6: null,
        unknownDest7: null,
        trackingError8: null,
        exceedMaxCircle9: null,
        gadTooSmall10: null,
        lengthError11: null,
        state13: null,
        state99: null,
        other: null,
        temp1: null,
        temp2: null,
        temp3: null,
        temp4: null,
        createDate: null,
        updateDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateDate = initRangeDate();
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加分拣状态统计";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWcs_sorted_status_percent(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改分拣状态统计";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWcs_sorted_status_percent(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWcs_sorted_status_percent(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除分拣状态统计编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delWcs_sorted_status_percent(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有分拣状态统计数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportWcs_sorted_status_percent(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        })
    }
  }
};
</script>
